/*
*Copyright 2021-2023 NERCIS
*
*Licensed under the Apache License, Version 2.0 (the "License");
*you may not use this file except in compliance with the License.
*You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*Unless required by applicable law or agreed to in writing, software
*distributed under the License is distributed on an "AS IS" BASIS,
*WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*See the License for the specific language governing permissions and
*limitations under the License.
*/

package cn.ac.nercis.pes.community.controller.manage;

import cn.ac.nercis.pes.community.config.AppConfig;
import cn.ac.nercis.pes.community.controller.base.InitDataLoad;
import cn.ac.nercis.pes.community.controller.project.TaskManageController;
import cn.ac.nercis.pes.community.support.FXMLController;
import cn.ac.nercis.pes.community.support.theme.ThemeManager;
import cn.ac.nercis.pes.community.utils.GuiStore;
import cn.ac.nercis.pes.community.utils.IconUtils;
import cn.ac.nercis.pes.community.utils.SpringUtils;
import cn.ac.nercis.pes.community.views.project.TaskManageView;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.image.ImageView;
import org.springframework.beans.factory.annotation.Autowired;

import java.net.URL;
import java.util.ResourceBundle;

/**
 * 关于控制器
 *
 * @author zpy
 * @version 1.0.0
 */
@FXMLController
public class AboutController implements Initializable, InitDataLoad {

    private final static String VERSION_PREFIX = "版本 ";
    @FXML
    private Button backButton;
    @FXML
    private ImageView aboutImg;
    @FXML
    private Label titleLabel;
    @FXML
    private Label appTitle;
    @FXML
    private Label appVersion;
    @FXML
    private Label appCopyright;

    private final AppConfig appConfig;

    @Autowired
    public AboutController(AppConfig appConfig) {
        this.appConfig = appConfig;
    }

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        titleLabel.setGraphic(IconUtils.getGlyph("about-icon", "title-icon"));
        backButton.setGraphic(IconUtils.getGlyph("back-button-icon", "btn-icon"));
        aboutImg.setImage(ThemeManager.config().getAboutImg());
    }

    @Override
    public void initializeData() {
        appTitle.setText(appConfig.getAppTitle());
        appVersion.setText(VERSION_PREFIX.concat(appConfig.getAppVersion()));
        appCopyright.setText(appConfig.getAppCopyright());
    }

    @FXML
    public void onBack() {
        var taskManageView = SpringUtils.getBean(TaskManageView.class).getView();
        GuiStore.setMainBodyContent(taskManageView);
    }
}